package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JToolBar;

import controller.EditeurActionController;
import controller.Interpreteur;

public class EditeurActionUI extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	EditeurActionController editeurActionController;
	Interpreteur interpreteur;
	
	
	public EditeurActionUI(final EditeurActionController editeurActionController, final Interpreteur interpreteur) {
		super();
		this.editeurActionController = editeurActionController;
		this.interpreteur = interpreteur;
		
		//this.setPreferredSize(new Dimension(250,400));
		JToolBar toolbar;
		
		JButton nouv = new JButton("Nouveau");
		nouv.setIcon(new ImageIcon("images/images/btn_new.png"));
		JButton open = new JButton("Ouvrir");
		open.setIcon(new ImageIcon("images/images/btn_tree_open.gif"));
		JButton save = new JButton("Enregistrer");
		save.setIcon(new ImageIcon("images/images/btn_menu_save_16.gif"));
		JButton undo = new JButton("Annuler");
		undo.setIcon(new ImageIcon("images/images/btn_menu_undo_16.gif"));
		JButton redo = new JButton("Répéter");
		redo.setIcon(new ImageIcon("images/images/btn_menu_redo_16.gif"));
		JButton execute = new JButton("Executer");
		execute.setIcon(new ImageIcon("images/images/btn_play.png"));
		
		//open.setPreferredSize(new Dimension(50,50));
		
		toolbar = new JToolBar();
		toolbar.add(nouv);
		toolbar.add(open);
		toolbar.add(save);
		toolbar.add(undo);
		toolbar.add(redo);
		toolbar.add(execute);
		
		this.add(toolbar);
		
		ActionListener pressUndo = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				editeurActionController.doUndo();
			}
		};
		
		ActionListener preesRedo = new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				editeurActionController.doRedo();
			}
		};
		
		
		ActionListener pressSave = new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				editeurActionController.doSave();
			}
		};
		
		ActionListener pressOpen = new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
					editeurActionController.doOpen();
	            }
		
		};
		
		ActionListener pressNouv = new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
					editeurActionController.doNouv();
	            }
		
		};
		
		ActionListener pressExecute = new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				interpreteur.doInterpreter();
			}
			
		};
		
		nouv.addActionListener(pressNouv);
		undo.addActionListener(pressUndo);
		redo.addActionListener(preesRedo);
		save.addActionListener(pressSave);
		open.addActionListener(pressOpen);
		execute.addActionListener(pressExecute);
	}
	

}
